package com.saint.farmshop.Mapper.MapperImpl;

import com.saint.farmshop.Entity.Order;
import com.saint.farmshop.Mapper.OrderMapper;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 订单映射器实现类
 *
 * @author Saint
 * @date 2022/06/30
 */
@Repository
public class OrderMapperImpl implements OrderMapper {

    @Resource
    MongoTemplate mongoTemplate;

    private final String COLLECTION_NAME = "order";

    @Override
    public boolean createOrder(Order order) {
        if(mongoTemplate.insert(order,COLLECTION_NAME) != null){
            return true;
        }
        else{
            return false;
        }
    }

    @Override
    public List<Order> getOrderList(String openId) {
        Criteria criteria = Criteria.where("userId").is(openId);
        Query query = new Query(criteria);
        return mongoTemplate.find(query,Order.class,COLLECTION_NAME);
    }


}
